package collection;

import java.util.*;

public class SortPoint {
    public static void main(String[] args) {
        Random random = new Random();
        List<Point> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(new Point(random.nextInt(10),random.nextInt(10)));
        }
        System.out.println(list);
        /*list.sort(new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                return 0;
            }
        });*/
        list.sort(((o1, o2) -> {
            int a = o1.getX()* o1.getX()+o1.getY()* o1.getY();
            int b = o2.getX()* o2.getX()+o2.getY()* o2.getY();
            return a-b;
        }));
        /*Collections.sort(list, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                int a = o1.getX()* o1.getX()+o1.getY()* o1.getY();
                int b = o2.getX()* o2.getX()+o2.getY()* o2.getY();
                return a-b;

            }
        });*/
        System.out.println(list);

    }
}
